﻿using DeZhen.DataCollection.IRepository.CollectionInstance;
using DeZhen.DataCollection.Model.Entities;
using SqlSugar;

namespace DeZhen.DataCollection.Repository.CollectionInstance
{
    public class CollectionInstanceDetailRepository : BaseRepository<CollectionInstanceDetail>, ICollectionInstanceDetailRepository
    {
        private ISqlSugarClient _db;
        public CollectionInstanceDetailRepository(ISqlSugarClient db) : base(db)
        {
            _db = db;
        }

        public async Task<List<CollectionInstanceDetail>> GetDetailByInstanceIdAsync(long collectionInstanceId)
        {
            return await _db.Queryable<CollectionInstanceDetail>()
                .Where(x => x.CollectionInstanceId == collectionInstanceId)
                .ToListAsync();
        }

        public async Task<List<CollectionInstanceDetail>> GetDetailByLatestInstanceIdAsync(long collectionInstanceId,long templateId,long templateDetailId) 
        {
            return await _db.Queryable<CollectionInstanceDetail>()
                .Where(x => x.CollectionInstanceId == collectionInstanceId)
                .Where(x => x.CollectionTemplateId == templateId && x.CollectionTemplateDetailId == templateDetailId)
                .ToListAsync();
        }

        //public async Task<bool> CreateManyAsync(List<CollectionInstanceDetail> createList)
        //{
        //    if (createList == null || createList.Count == 0)
        //        return false;

        //    var result = await _db.Insertable(createList).ExecuteCommandAsync();
        //    return result > 0;
        //}
    }
}
